package com.zr.controller.order;

import com.zr.service.order.OrderFeeService;
import com.zr.utils.AjaxResult;
import com.zr.vo.order.OrderFee;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 订单费用处理
 * @author huangguilong
 */
@RestController
@RequestMapping("/order/fee")
public class OrderFeeController {

    @Resource
    private OrderFeeService orderFeeService;

    /**
     * 根据订单编号查询费用列表
     * @param orderId
     * @return map
     * @author huangguilong
     */
    @RequestMapping("/list/{orderId}")
    public AjaxResult list(@PathVariable("orderId") String orderId) {
        Map<String, Object> map = orderFeeService.getFeeByOrderId(orderId);
        return AjaxResult.success(200, "查询成功", map);
    }

    /**
     * 新增费用
     * @param orderId
     * @param orderFee
     * @return
     * @author huangguilong
     */
    @RequestMapping("/add/{orderId}")
    public AjaxResult add(@PathVariable("orderId") String orderId, @RequestBody OrderFee orderFee) {
        orderFee.setFeeOrderId(orderId);
        orderFeeService.add(orderFee);
        return AjaxResult.success(200, "新增成功", null);
    }

    /**
     * 删除费用
     * @param orderFee
     * @return
     * @author huangguilong
     */
    @RequestMapping("/remove")
    public AjaxResult remove(@RequestBody OrderFee orderFee) {
        orderFeeService.remove(orderFee);
        return AjaxResult.success(200, "删除成功", null);
    }

    /**
     * 删除所有未生成委托订单的费用信息
     * @return
     * @author huangguilong
     */
    @RequestMapping("/clearFeeList")
    public AjaxResult clearFeeList() {
        orderFeeService.deleteAllByOrderId();
        return AjaxResult.success(200, "删除成功", null);
    }

}
